package com.sentinel.sentineltest.controller;

import com.alibaba.csp.sentinel.Entry;
import com.alibaba.csp.sentinel.SphU;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import com.alibaba.csp.sentinel.slots.block.BlockException;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;

@RestController
@RequestMapping("/sentinel")
public class DemoController {

    @SentinelResource(value = "sayHello")
    @RequestMapping("test1")
    public String test1(){
        return "OK";
    }
    @RequestMapping("/test")
    public String test(){
        Entry entry = null;
        try {
            entry = SphU.entry("HelloWorld");
            /*您的业务逻辑 - 开始*/
            System.out.println("success");
            /*您的业务逻辑 - 结束*/
        } catch (BlockException e1) {
            System.out.println("error");
            /*流控逻辑处理 - 开始*/
            return "Fail";
            /*流控逻辑处理 - 结束*/
        } finally {
            if (entry != null) {
                entry.exit();
            }
        }
        return "OK";
    }
}
